﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.DXErrorProvider;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmEditCode : XtraForm
    {
        private SimpleButton btCancel;
        private SimpleButton btCreate;
        private IContainer components;
        private DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider Err;
        private GroupBox groupBox1;
        private DevExpress.Utils.ImageCollection imageCollection1;
        private LabelControl labelControl1;
        private LabelControl labelControl2;
        private LabelControl labelControl3;
        private LabelControl lcDescription;
        private PanelControl panelControl1;
        private TextEdit txtNewEmployeeCode;
        private TextEdit txtOldEmployeeCode;
        private LabelControl txtWaiting;

        public event SuccessEventHander Success;

        public xfmEditCode()
        {
            this.components = null;
            this.InitializeComponent();
        }

        public xfmEditCode(string OldEmployeeCode)
        {
            this.components = null;
            this.InitializeComponent();
            this.txtOldEmployeeCode.Text = OldEmployeeCode;
            this.txtNewEmployeeCode.Focus();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btCreate_Click(object sender, EventArgs e)
        {
            this.txtWaiting.Visible = true;
            if (this.txtNewEmployeeCode.Text == "")
            {
                this.Err.SetError(this.txtNewEmployeeCode, "M\x00e3 kh\x00f4ng được rỗng");
                XtraMessageBox.Show("M\x00e3 nh\x00e2n vi\x00ean kh\x00f4ng được rỗng!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK);
                this.txtNewEmployeeCode.Focus();
                this.txtWaiting.Visible = false;
            }
            else
            {
                HRM_EMPLOYEE item = new HRM_EMPLOYEE();
                if (item.Exist(this.txtNewEmployeeCode.Text))
                {
                    this.Err.SetError(this.txtNewEmployeeCode, "M\x00e3 đ\x00e3 tồn tại.");
                    XtraMessageBox.Show("M\x00e3 nh\x00e2n vi\x00ean đ\x00e3 tồn tại!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK);
                    this.txtNewEmployeeCode.Focus();
                    this.txtWaiting.Visible = false;
                }
                else if (item.EditCode(this.txtOldEmployeeCode.Text, this.txtNewEmployeeCode.Text) == "OK")
                {
                    item.Get(this.txtNewEmployeeCode.Text);
                    this.RaiseSuccessEventHander(item);
                    this.txtWaiting.Visible = false;
                    base.Close();
                }
                else
                {
                    this.txtWaiting.Visible = false;
                    XtraMessageBox.Show("Qu\x00e1 tr\x00ecnh sửa m\x00e3 nh\x00e2n vi\x00ean đ\x00e3 xảy ra lỗi! Chương tr\x00ecnh kh\x00f4ng thể sửa m\x00e3 nh\x00e2n vi\x00ean n\x00e0y!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmEditCode));
            this.btCreate = new SimpleButton();
            this.imageCollection1 = new DevExpress.Utils.ImageCollection(this.components);
            this.btCancel = new SimpleButton();
            this.lcDescription = new LabelControl();
            this.panelControl1 = new PanelControl();
            this.labelControl2 = new LabelControl();
            this.labelControl3 = new LabelControl();
            this.groupBox1 = new GroupBox();
            this.txtNewEmployeeCode = new TextEdit();
            this.txtOldEmployeeCode = new TextEdit();
            this.labelControl1 = new LabelControl();
            this.Err = new DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider(this.components);
            this.txtWaiting = new LabelControl();
            this.imageCollection1.BeginInit();
            this.panelControl1.BeginInit();
            this.panelControl1.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.txtNewEmployeeCode.Properties.BeginInit();
            this.txtOldEmployeeCode.Properties.BeginInit();
            ((ISupportInitialize) this.Err).BeginInit();
            base.SuspendLayout();
            this.btCreate.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btCreate.ImageIndex = 2;
            this.btCreate.ImageList = this.imageCollection1;
            this.btCreate.Location = new Point(0xb0, 10);
            this.btCreate.Name = "btCreate";
            this.btCreate.Size = new Size(0x6a, 0x17);
            this.btCreate.TabIndex = 2;
            this.btCreate.Text = "Đồng \x00dd (>>)";
            this.btCreate.Click += new EventHandler(this.btCreate_Click);
            this.imageCollection1.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection1.ImageStream");
            this.imageCollection1.Images.SetKeyName(0, "ico_alpha_Search_16x16.png");
            this.imageCollection1.Images.SetKeyName(1, "ico_alpha_Delete_16x16.png");
            this.imageCollection1.Images.SetKeyName(2, "document2.png");
            this.imageCollection1.Images.SetKeyName(3, "open-16x16.png");
            this.imageCollection1.Images.SetKeyName(4, "close.png");
            this.btCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btCancel.ImageIndex = 4;
            this.btCancel.ImageList = this.imageCollection1;
            this.btCancel.Location = new Point(0x12a, 10);
            this.btCancel.Name = "btCancel";
            this.btCancel.Size = new Size(0x62, 0x17);
            this.btCancel.TabIndex = 3;
            this.btCancel.Text = "Tho\x00e1t";
            this.btCancel.Click += new EventHandler(this.btCancel_Click);
            this.lcDescription.AllowHtmlString = true;
            this.lcDescription.Appearance.Options.UseTextOptions = true;
            this.lcDescription.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.lcDescription.AutoSizeMode = LabelAutoSizeMode.None;
            this.lcDescription.Location = new Point(0x11, 5);
            this.lcDescription.Name = "lcDescription";
            this.lcDescription.Size = new Size(0x17b, 0x38);
            this.lcDescription.TabIndex = 4;
            this.lcDescription.Text = "    Nhập m\x00e3 nh\x00e2n vi\x00ean mới v\x00e0o \x00f4 <i>M\x00e3 mới</i> sau đ\x00f3 nhấn n\x00fat <i>Đồng \x00dd</i> b\x00ean dưới để thay đổi m\x00e3 cho nh\x00e2n vi\x00ean. Lưu \x00fd: m\x00e3 nh\x00e2n vi\x00ean mới kh\x00f4ng được tr\x00f9ng với m\x00e3 của c\x00e1c nh\x00e2n vi\x00ean c\x00f2n lại.";
            this.panelControl1.Appearance.BackColor = Color.Transparent;
            this.panelControl1.Appearance.Options.UseBackColor = true;
            this.panelControl1.BorderStyle = BorderStyles.NoBorder;
            this.panelControl1.Controls.Add(this.txtWaiting);
            this.panelControl1.Controls.Add(this.btCancel);
            this.panelControl1.Controls.Add(this.btCreate);
            this.panelControl1.Dock = DockStyle.Bottom;
            this.panelControl1.Location = new Point(0, 0xc7);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new Size(0x19b, 0x2b);
            this.panelControl1.TabIndex = 6;
            this.labelControl2.Location = new Point(0x12, 0x1f);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x20, 13);
            this.labelControl2.TabIndex = 15;
            this.labelControl2.Text = "M\x00e3 cũ:";
            this.labelControl3.Location = new Point(0x12, 0x40);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x25, 13);
            this.labelControl3.TabIndex = 0x10;
            this.labelControl3.Text = "M\x00e3 mới:";
            this.groupBox1.Controls.Add(this.txtNewEmployeeCode);
            this.groupBox1.Controls.Add(this.txtOldEmployeeCode);
            this.groupBox1.Controls.Add(this.labelControl3);
            this.groupBox1.Controls.Add(this.labelControl2);
            this.groupBox1.Location = new Point(0x11, 0x3b);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x17e, 0x61);
            this.groupBox1.TabIndex = 0x13;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Nhập m\x00e3 thay đổi";
            this.txtNewEmployeeCode.Location = new Point(0x48, 0x3d);
            this.txtNewEmployeeCode.Name = "txtNewEmployeeCode";
            this.txtNewEmployeeCode.Size = new Size(0x123, 20);
            this.txtNewEmployeeCode.TabIndex = 0x12;
            this.txtNewEmployeeCode.EditValueChanged += new EventHandler(this.txtNewEmployeeCode_EditValueChanged);
            this.txtOldEmployeeCode.Enabled = false;
            this.txtOldEmployeeCode.Location = new Point(0x48, 0x1d);
            this.txtOldEmployeeCode.Name = "txtOldEmployeeCode";
            this.txtOldEmployeeCode.Size = new Size(0x123, 20);
            this.txtOldEmployeeCode.TabIndex = 0x11;
            this.labelControl1.AllowHtmlString = true;
            this.labelControl1.Appearance.Options.UseTextOptions = true;
            this.labelControl1.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl1.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl1.Location = new Point(0x11, 0xa4);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x17b, 0x1d);
            this.labelControl1.TabIndex = 20;
            this.labelControl1.Text = "    <color=OrangeRed>Cẩn thận:</color> Qu\x00e1 tr\x00ecnh thay đổi m\x00e3 c\x00f3 thể ph\x00e1t sinh lỗi. Vui l\x00f2ng sao lưu lại dữ liệu trước khi thực hiện chức năng n\x00e0y.";
            this.Err.ContainerControl = this;
            this.txtWaiting.Location = new Point(0x11, 0x11);
            this.txtWaiting.Name = "txtWaiting";
            this.txtWaiting.Size = new Size(0x42, 13);
            this.txtWaiting.TabIndex = 4;
            this.txtWaiting.Text = "Vui l\x00f2ng đợi...";
            this.txtWaiting.Visible = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x19b, 0xf2);
            base.Controls.Add(this.labelControl1);
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.panelControl1);
            base.Controls.Add(this.lcDescription);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmEditCode";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Thay đổi m\x00e3 nh\x00e2n vi\x00ean";
            this.imageCollection1.EndInit();
            this.panelControl1.EndInit();
            this.panelControl1.ResumeLayout(false);
            this.panelControl1.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.txtNewEmployeeCode.Properties.EndInit();
            this.txtOldEmployeeCode.Properties.EndInit();
            ((ISupportInitialize) this.Err).EndInit();
            base.ResumeLayout(false);
        }

        private void RaiseSuccessEventHander(HRM_EMPLOYEE item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        private void txtNewEmployeeCode_EditValueChanged(object sender, EventArgs e)
        {
            TextEdit control = (TextEdit) sender;
            if (control.ErrorText != string.Empty)
            {
                this.Err.SetError(control, string.Empty);
            }
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            if (hrm_employee.Exist(control.Text))
            {
                this.Err.SetError(control, "M\x00e3 đ\x00e3 tồn tại.");
                control.Focus();
            }
        }

        public delegate void SuccessEventHander(object sender, HRM_EMPLOYEE item);
    }
}

